package com.ruoyi.system.service.impl.fxImpl;

import com.ruoyi.system.domain.fx.FxOrder;
import com.ruoyi.system.domain.fx.FxOrderDada;
import com.ruoyi.system.mapper.fx.FxOrderDadaMapper;
import com.ruoyi.system.service.fx.IFxOrderDadaService;
import com.ruoyi.system.service.fx.IFxOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 达达配送订单记录Service业务层处理
 *
 * @author ruoyi
 * @date 2025-03-27
 */
@Service
public class FxOrderDadaServiceImpl implements IFxOrderDadaService
{
    @Autowired
    private FxOrderDadaMapper fxOrderDadaMapper;

    @Autowired
    private IFxOrderService fxOrderService;

    /**
     * 查询达达配送订单记录
     *
     * @param orderId 达达配送订单记录主键
     * @return 达达配送订单记录
     */
    @Override
    public FxOrderDada selectFxOrderDadaByOrderId(String orderId)
    {
        return fxOrderDadaMapper.selectFxOrderDadaByOrderId(orderId);
    }

    /**
     * 查询达达配送订单记录列表
     *
     * @param fxOrderDada 达达配送订单记录
     * @return 达达配送订单记录
     */
    @Override
    public List<FxOrderDada> selectFxOrderDadaList(FxOrderDada fxOrderDada)
    {
        return fxOrderDadaMapper.selectFxOrderDadaList(fxOrderDada);
    }

    /**
     * 新增达达配送订单记录
     *
     * @param fxOrderDada 达达配送订单记录
     * @return 结果
     */
    @Override
    @Transactional
    public int insertFxOrderDada(FxOrderDada fxOrderDada)
    {
        int i = fxOrderDadaMapper.insertFxOrderDada(fxOrderDada);
        //修改订单为派送中
        FxOrder fxOrder = new FxOrder();
        fxOrder.setId(fxOrderDada.getOrderId());
        if (fxOrderDada.getOrderStatus().equals(3)){//达达配送中
            fxOrder.setOrderStatus(2L);//订单配送中
        }else if (fxOrderDada.getOrderStatus().equals(4)){//达达已完成
            fxOrder.setOrderStatus(4L);//订单已完成
        }else{
            fxOrder.setOrderStatus(1L);//待接单
        }

        int i1 = fxOrderService.updateFxOrder(fxOrder);
        if (i1==0){
            System.err.println("达达配送 修改订单状态失败 单号为："+fxOrderDada.getOrderId());
        }
        return i;
    }

    /**
     * 修改达达配送订单记录
     *
     * @param fxOrderDada 达达配送订单记录
     * @return 结果
     */
    @Override
    public int updateFxOrderDada(FxOrderDada fxOrderDada)
    {
        return fxOrderDadaMapper.updateFxOrderDada(fxOrderDada);
    }

    /**
     * 批量删除达达配送订单记录
     *
     * @param orderIds 需要删除的达达配送订单记录主键
     * @return 结果
     */
    @Override
    public int deleteFxOrderDadaByOrderIds(String[] orderIds)
    {
        return fxOrderDadaMapper.deleteFxOrderDadaByOrderIds(orderIds);
    }

    /**
     * 删除达达配送订单记录信息
     *
     * @param orderId 达达配送订单记录主键
     * @return 结果
     */
    @Override
    public int deleteFxOrderDadaByOrderId(String orderId)
    {
        return fxOrderDadaMapper.deleteFxOrderDadaByOrderId(orderId);
    }
}
